﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SilentVoice.Business;
using SilentVoice.Models;
using System.Security.Principal;
using SilentVoice.Security;

namespace SilentVoice.Service.Handlers
{
    public class BasicPrincipalProvider : IProvidePrincipal
    {
        private Business.Security manager;

        public BasicPrincipalProvider()
        {
            manager = new Business.Security();
        }

        public IPrincipal CreatePrincipal(string username, string password)
        {
            User user = manager.Login(username, password);
            var identity = new GenericIdentity(user.Email);
            
            Role role = manager.GetRole(user);

            IPrincipal principal = new SVPrincipal(identity, user, role);

            return principal;
        }
    }
}